package com.kinyx.framework.bean;

import java.util.function.BiFunction;

import org.junit.Assert;
import org.junit.Test;

public class KeyValus_Tester_ {

	@Test
	public void test() {
		this.method(null);
		this.method("key");
	}

	private void method(final String key) {
		final BiFunction<String, Integer, String> converter = (str, idx) -> { return "(" + str + ")"; };

		Assert.assertTrue(KeyValues.of().get(key, null, null) == null);

		Assert.assertTrue(KeyValues.of().add(key, "foo").get(key, null, null).equals("foo"));
		Assert.assertTrue(KeyValues.of().add(key, "foo").get(key, null, converter).equals("(foo)"));

		Assert.assertTrue(KeyValues.of().add(key, "foo").clear().get(key, null, null) == null);
		Assert.assertTrue(KeyValues.of().add(key, "foo").clear().get(key, null, converter) == null);

		Assert.assertTrue(KeyValues.of().add(key, "foo").clear().add(key, "bar").get(key, null, null).equals("bar"));
		Assert.assertTrue(KeyValues.of().add(key, "foo").clear().add(key, "bar").get(key, null, converter).equals("(bar)"));

		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").get(key, null, null).equals("foo,bar"));
		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").get(key, null, converter).equals("(foo),(bar)"));

		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").get(key, "|", null).equals("foo|bar"));
		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").get(key, "|", converter).equals("(foo)|(bar)"));

		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").add(key, null).get(key, null, null).equals("foo,bar,null"));
		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").add(key, null).get(key, null, converter).equals("(foo),(bar),(null)"));

		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").add(key, null).get(key, "|", null).equals("foo|bar|null"));
		Assert.assertTrue(KeyValues.of().add(key, "foo").add(key, "bar").add(key, null).get(key, "|", converter).equals("(foo)|(bar)|(null)"));

		Assert.assertTrue(KeyValues.of().add(key, null).add(key, "foo").add(key, "bar").add(key, null).get(key, null, null).equals("null,foo,bar,null"));
		Assert.assertTrue(KeyValues.of().add(key, null).add(key, "foo").add(key, "bar").add(key, null).get(key, null, converter).equals("(null),(foo),(bar),(null)"));

		Assert.assertTrue(KeyValues.of().add(key, null).add(key, "foo").add(key, "bar").add(key, null).get(key, "|", null).equals("null|foo|bar|null"));
		Assert.assertTrue(KeyValues.of().add(key, null).add(key, "foo").add(key, "bar").add(key, null).get(key, "|", converter).equals("(null)|(foo)|(bar)|(null)"));
	}

}
